import 'package:casdon/modules/me/data/model/user_center_model.dart';
import 'package:casdon/modules/me/domain/usecase/user_center_usecase.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class UserCenterNotifier extends Notifier<UserCenterModel> {
  Future<UserCenterModel> fetchData() async {
    final usercenterApi = await ref.read(userCenterUsecaseProvider).execute();
    if (usercenterApi == null) {
      state = UserCenterModel.initial();
    } else {
      state = UserCenterModel.fromApi(usercenterApi);
    }

    return state;
  }

  @override
  UserCenterModel build() {
    return UserCenterModel.initial();
  }
}

final userCenterNotifierProvider =
    NotifierProvider<UserCenterNotifier, UserCenterModel>(() {
      return UserCenterNotifier();
    });
